<?php
/*
 * 积分管理
 * @arrange Mark
 * @package ixdcw
 * @file    credit.inc.php
 * @time    12-12-19 上午11:01
 */
defined('IN_IXDCW') or exit('Access Denied');
login();
require DT_CORE.'/'.$module.'/common.inc.php';
require_once DT_INC.'/post.func.php';
switch($action) {
	default:
		$sfields = $L['credit_fields'];
		$dfields = array('reason', 'amount', 'reason', 'note');
		isset($fields) && isset($dfields[$fields]) or $fields = 0;
		isset($fromtime) or $fromtime = '';
		isset($totime) or $totime = '';
		isset($type) or $type = 0;
		$fields_select = dselect($sfields, 'fields', '', $fields);
		$condition = "username='$_username'";
		if($keyword) $condition .= " AND $dfields[$fields] LIKE '%$keyword%'";
		if($fromtime) $condition .= " AND addtime>".(strtotime($fromtime.' 00:00:00'));
		if($totime) $condition .= " AND addtime<".(strtotime($totime.' 23:59:59'));
		if($type) $condition .= $type == 1 ? " AND amount>0" : " AND amount<0" ;
		$r = $db->getOne("SELECT COUNT(*) AS num FROM {$db->getPre()}finance_credit WHERE $condition");
		$pages = pages($r['num'], $page, $pagesize);		
		$records = array();
		$result = $db->query("SELECT * FROM {$db->getPre()}finance_credit WHERE $condition ORDER BY itemid DESC LIMIT $offset,$pagesize");
		$income = $expense = 0;
		while($r = $db->fetchArray($result)) {
			$r['addtime'] = timetodate($r['addtime'], 5);
			$r['amount'] > 0 ? $income += $r['amount'] : $expense += $r['amount'];
			$records[] = $r;
		}
		$head_title = $L['credit_title'];
	break;
}
include template('credit', $module);
?>